package com.ebupt.migu.music.outside.service.impl;

import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.common.exception.MyException;
import com.ebupt.migu.music.common.exception.StatusEnum;
import com.ebupt.migu.music.outside.mapper.CMSMapper;
import com.ebupt.migu.music.outside.service.CMSService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Intellij IDEA.
 * User:  liuyangyang@cd.ebupt.com
 * Date:  2019/9/25
 */
@Slf4j
@Service
public class CMSServiceImpl implements CMSService {

    @Autowired
    private CMSMapper cmsMapper;

    /**
     * 查询指定点位活动列表
     *
     * @param params
     * @return
     */
    @Override
    public ResultObject activities(Map<String, Object> params) {
        // position： 1- Banner； 2- 音乐之声；
        if (null == params.get("position")) {
            throw new MyException(StatusEnum.BUSINID, "点位不可为空");
        }
        String position = params.get("position").toString();
        String activityName = null;
        if (null != params.get("activityName")){
            activityName = params.get("activityName").toString();
        }
        ResultObject<Object> res = new ResultObject<>();
        List<HashMap<String, Object>> activities;
        try {
            switch (position) {
                case "1":
                    activities = cmsMapper.activities("首页Banner", activityName);
                    break;
                case "2":
                    activities = cmsMapper.activities("音乐之声（新）", activityName);
                    break;
                default:
                    res.setCode(StatusEnum.BUSINID.getCode());
                    res.setMsg("点位填写错误");
                    return res;
            }
        }catch (Exception e){
            log.error("查询活动列表失败",e);
            throw new MyException(StatusEnum.ERROR, "查询活动列表失败");
        }
        res.setMsg("查询成功");
        res.setData(activities);
        return res;
    }
}
